<template>
	<view>
		<view class="dsr">
			单位信息
		</view>
		<view class="contentView flex-row-space-between" style="margin-top: 20rpx;">
			<view class="name">
				单位名称
			</view>
			<input @input="textInput" :disabled="isEdit" v-model="infoDic.unitname" class="inputView" placeholder="请输入"/>
		</view>
		<view class="contentView flex-row-space-between" style="margin-top: 20rpx;">
			<view class="name">
				法人/负责人
			</view>
			<input @input="textInput" :disabled="isEdit" v-model="infoDic.unitlegalpersons" class="inputView" placeholder="请输入"/>
		</view>
		<view class="contentView flex-row-space-between">
			<view class="name">
				统一社会信用代码
			</view>
			<input @input="textInput" :disabled="isEdit" v-model="infoDic.unitcreditcode" class="inputView" placeholder="选填"/>
		</view>
		<view class="contentView flex-row-space-between">
			<view class="name">
				联系方式
			</view>
			<input @input="textInput" :disabled="isEdit" v-model="infoDic.unitcontact" class="inputView" placeholder="请输入"/>
		</view>
		<view class="contentView flex-row-space-between">
			<view class="name">
				营业执照/许可证
			</view>
			<view class=""></view>
		</view>
		<view class="contentView2 flex-row-flex-start">
			<view class="flex-column-center" style="width: 336rpx;">
				<image @click="choosePicClick(3)" class="frontbackIcon" :src="infoDic.businesslicense?infoDic.businesslicense:'/static/shangchuan_zhengmian.png'"></image>
			</view>
		</view>
		<view class="contentView flex-row-space-between">
			<view class="name">
				法人/负责人身份证
			</view>
			<view class=""></view>
		</view>
		<view class="contentView2 flex-row-space-between">
			<view class="flex-column-center" style="width: 336rpx;">
				<image @click="choosePicClick(1)" class="frontbackIcon" :src="infoDic.legalpersonsidcardfront?infoDic.legalpersonsidcardfront:'/static/shangchuan_zhengmian.png'"></image>
				<view class="frontbackText">身份证正面</view>
			</view>
			<view class="flex-column-center" style="width: 336rpx;">
				<image @click="choosePicClick(2)" class="frontbackIcon" :src="infoDic.legalpersonsidcardreverse?infoDic.legalpersonsidcardreverse:'/static/shangchuan_zhengmian.png'"></image>
				<view class="frontbackText">身份证反面</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"danWeiXinXi",
		props: {
			//当前组件内容信息
			/*
			unitname
			string 
			单位名称
			可选
			unitlegalpersons
			string 
			法人/负责人
			可选
			unitcreditcode
			string 
			统一社会信用代码
			可选
			unitcontact
			string 
			联系方式
			可选
			businesslicense
			string 
			营业许可证
			可选
			legalpersonsidcardfront
			string 
			法人身份证正
			可选
			legalpersonsidcardreverse
			string 
			法人身份证反

			*/
			infoDic: {
				type: Object,
				default: function() {
					return {
						unitname: '',
						unitlegalpersons: '',
						unitcreditcode:'',
						unitcontact:'',
						businesslicense: '',
						legalpersonsidcardfront:'',
						legalpersonsidcardreverse:''
					};
				}
			},
			//当前组件是否可编辑
			isEdit: {
				type: Boolean,
				default: false,
			},
		},
		data() {
			return {
				
			};
		},
		methods:{
			choosePicClick(index){//1正面   2反面
				if (this.isEdit==true) {
					return
				}
				let token = uni.getStorageSync('token')
				uni.showLoading({mask: true})
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					success: chooseImageRes => {
						let header = {};
						if(token){
							header = {'token':token};
						}
						const tempFilePaths = chooseImageRes.tempFilePaths;
						for (let i = 0; i < tempFilePaths.length; i++) {
							uni.uploadFile({
								url: `https://api.test.yidianchen.com/lawyer/api/sys/oss/upload`,
								filePath: tempFilePaths[i],
								name: 'file',
								header:header,
								formData: {
									'user': 'test'
								},
								success: uploadFileRes => {
									uni.hideLoading()
									let res1 = JSON.parse(uploadFileRes.data);
									let data1 = res1.data.fileUrl;
									console.log('res1',res1)
									if (index==1) {//1正面   2反面
										this.infoDic.legalpersonsidcardfront = data1
									} else if (index==2){
										this.infoDic.legalpersonsidcardreverse = data1
									}
									else{
										this.infoDic.businesslicense = data1
									}
									this.textInput()
								},
								fail() {
									uni.hideLoading()
								}
							});
						}
					},
					fail: (error) => {
						uni.hideLoading()
					}
				});
			},
			textInput(){
				console.log('this.infoDic----',this.infoDic)
				this.$emit('danWeiInfoCallBack', this.infoDic)
			}
		}
	}
</script>

<style>
	.frontbackIcon{
		width: 336rpx;
		height: 200rpx;
	}
	.frontbackText{
		margin-top: 18rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #999999;
	}
	.inputView{
		width: 440rpx;
		margin-left: 12rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;
		text-align: right;
	}
	.name{
		width: 250rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;
	}
	
	.contentView{
		padding-left: 24rpx;
		padding-right: 24rpx;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}
	.contentView2{
		padding-left: 24rpx;
		padding-right: 24rpx;
		padding-top: 10rpx;
		padding-bottom: 20rpx;
	}
	.dsr{
		margin-left: 24rpx;
		margin-top: 40rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 32rpx;
		color: #333333;
	}
</style>